<?

/********************************************
* match.php
*
* This page will display an embeded player for a given match
* the participants, who won, and a download link.
*
********************************************/

//include files
include "config.php";
include "../lib/db.php";
include "../lib/tbatv_lib.php";

$tba = new tbatvController();

//get passed arguments
$matchid = sanatizeGet($_GET['matchid']);
if ($matchid == "") {
	$matchid = sanatizeGet($_GET['match']);
} 
if ($matchid == "") {
    $matchid = 0;
}
$match = new Match($matchid);
$event = $match->getEvent();
$redalliance = $match->getTeams("red");
$bluealliance = $match->getTeams("blue");

//set up header
$title = " - " . $match->getName();
$linkedfromiframe = 1;

include "header.php";

//Echo the match information
?>
<h1><? echo $event->linkto() ?></h1>
<h2><? echo $match->getName() ?> <a href="javascript: history.go(-1)" class="back">(back)</a></h2>
<div class="leftfloat">
	<table class="matchteams">
		<tr>
			<td class="redteamname">Red</td>
			<td class="blueteamname">Blue</td>
		</tr><tr>
			<td class="red"><? echo $tba->linkTeam($redalliance[0]) ?></td>
			<td class="blue"><? echo $tba->linkTeam($bluealliance[0]) ?></td>
		</tr><tr>
			<td class="red"><? echo $tba->linkTeam($redalliance[1]) ?></td>
			<td class="blue"><? echo $tba->linkTeam($bluealliance[1]) ?></td>
		</tr><tr>
			<td class="red"><? echo $tba->linkTeam($redalliance[2]) ?></td>
			<td class="blue"><? echo $tba->linkTeam($bluealliance[2]) ?></td>
		</tr><tr>
			<td class="matchscore"><? echo $match->getRedScore() ?></td>
			<td class="matchscore"><? echo $match->getBlueScore() ?></td>
		</tr>
	</table>
	<p>(click a team for detailed info)</p>
	<br />
	<? 
    //echo the download link	
    if ($match->getVidPath() != Null) { ?>
    		<p><a href="<? echo $match->getVidPath() ?>" title="<? echo $match->getName() ?>"><img src="<? echo $BASE_PATH ?>images/video_icon.png" style="float: left; margin: 8px 5px 0 0; padding: 0 0 16px 0;"> right click to download (<? echo $match->getVidSize() ?>MB).</a></p>
    	<? } else { ?>
    		<p>This video is not yet available for download.</p>
    	<? } ?>
    </div>

    <? 
    //echo the flash player

    if ($match->getFlvPath() != Null) {
    	$filepath = $match->getFlvPath();
    	$imagepath = $match->getThumbPath();
    } else {
    	$filepath = $BASE_PATH . "images/notavailable.flv";
    	$imagepath = $BASE_PATH . "images/notavailable.jpg";
    }
    ?>
    <script type="text/javascript" src="<? echo $BASE_PATH ?>scripts/swfobject.js"></script><? //this is needed for the flash player ?>
	<p id="player"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
	var s1 = new SWFObject("<? echo $BASE_PATH ?>flvplayer.swf","single","380","304","7");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allownetworking","all");
	s1.addParam("allowscriptaccess","always");
	s1.addParam("viral.callout","mouse");
	s1.addVariable("file","<? echo $filepath ?>");
	s1.addVariable("image","<? echo $imagepath ?>");
	s1.addVariable("width","380");
	s1.addVariable("height","304");
	s1.addVariable("displayheight","285");
	s1.write("player");
</script>
<?
if ($match->getThanks() != "") {
//echo the thanks
	?>
	<p>Video of this event is provided courtesy of <? echo $match->getThanks() ?>.</p>
	<?
}
include "footer.php";
?>